﻿#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include "Head.h"
#include <QMainWindow>
#include <QSerialPortInfo>
#include <QSerialPort>
#include <QMessageBox>
#include <QSettings>
#include <QSqlDatabase>
#include <QSqlError>
#include <QSqlQuery>
#include <QDateTime>
#include <QSystemTrayIcon>
#include <QFileDialog>
#include <QDesktopServices>
#include <QProgressBar>
#include <QTableWidget>
#include <QList>

#include "ipextend.h"
#include "SpectroMeter/spectrometertableviewwrap.h"
#include "SpectroMeter/spectrometerdata.h"
#include "spectrumplotwrap.h"
#include "SpectroMeter/SpectroMeterControl.h"
#include "GlobalVar.h"
#include "ConsumerWorker.h"

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

private slots:
    void Log(QString Log);

    void on_action_oepnConfigFile_triggered();

    void on_btnRun_clicked();

    void on_btnStop_clicked();

    void on_btnSearchDevice_clicked();

    void on_btnDataImport_clicked();

    void on_horizontalSlider_sliderMoved(int position);

    void AnalysisResolution();

    void on_btnSelectSaveRoot_clicked();

    void on_cmbTestId_activated(int index);

//    void on_cmbTestId_activated(const QString &arg1);

    void on_actionHelp_triggered();

    void on_tableWidgetSpectroInfo_clicked(const QModelIndex &index);

    void on_btnSetParam_clicked();

    void on_actionDataTrans_triggered();

    void on_radSoft_clicked();

    void on_radHard_clicked();

    void on_btnSetParams_clicked();

    void on_btnSetBlank_clicked();

    void on_btnSoftTrigger_clicked();

    void onProcessingFinished(const QString &statusMessage);

protected:
    void closeEvent(QCloseEvent *event) override;
signals:
    void stopSignal();
private:
    Ui::MainWindow *ui;

    QSystemTrayIcon  *trayIcon=nullptr;
    QStringList _exportKeys;
    AvsMeasPara _measPara;
    QSystemTrayIcon* CreateTrayIcon();

    QStandardItemModel *_spectroListModel = nullptr;
    SpectroMeterTableViewWrap *_viewWrap=nullptr;
    AvsMeasResultList _measuredData;
    AvsMeasResultList _processedData;
    SpectrumPlotWrap *_plotWrap=nullptr;
    AvsMeasPara GetMeasParam();
    void SetMeasParam(AvsMeasPara para);
    void SetSpectroControl(bool enabled);
    void SaveSpectrum(QString dirName);
    void Analysis(AvsMeasResultList data, QString type);
    MeasureParam GetMeasureParam();
    MeasureParam SetMeasureParam(MeasureParam p);

    QSettings *_set=nullptr;
    SpectroMeterControl *_spectroControl=nullptr;
    BaseSpectroMeter* _currentMeter=nullptr;

    QList<qreal> _datas;
    // QObject interface

    bool _stop;
    QMutex _measMutex;
    QWaitCondition _measCondition;
    QMutex _procMutex;
    QWaitCondition _procCondition;
    void StartSave();
    QString _dirName;
    QString _firstSN;
    int _totalPixelNumber;




protected:
    virtual void timerEvent(QTimerEvent *event) override;
};

#endif // MAINWINDOW_H
